/**
 * 定义分析仪监测项管理模块
 */
(function(window, angular, undefined) {
	var Module = angular.module(
			'water.apps.sw.systemConfig.monitorEquipmentDictParam.monitorEquipmentDictParamManager',
			[ 'water.entity.monitorEquipmentDictParam' ]);

	Module.controller('monitorEquipmentDictParamManagerController', function(
			$rootScope, $scope, $monitorEquipmentDictParamService) {

		/**
		 * 新建model
		 */
		$scope.createModel={};
		/**
		 * 编辑model
		 */
		$scope.editModel={};
		/**
		 * 分析仪监测项表数据
		 */
		$scope.dataList=[];
		/**
		 * 编辑对话框对象
		 */
		$scope.editDialog;
		/**
		 * 详情对话框对象
		 */
		$scope.detailDialog;
		/**
		 * 新增对话框
		 */
		$scope.createDialog;
		
		/**
		 * 新增按钮点击事件
		 */
		$scope.onCreateClick = function() {
			$scope.createDialog.open();
		}
		/**
		 * 提交事件
		 */
		$scope.onSubmitCreateClick = function(model) {
			model={"EQUIPMENT_ID":model.EQUIPMENT_ID,"PARAM_CODE":model.PARAM_CODE[0]};
			$monitorEquipmentDictParamService.createModel(model).then(function() {
				console.log("#############4");
				$.messager.alert("保存成功", "保存成功", 'info');
				$scope.createDialog.close();
				_getList();
			});
		}
		/**
		 * 提交并创建事件
		 */
		$scope.onSubmitCreateNextClick = function(model) {
			model={"EQUIPMENT_ID":model.EQUIPMENT_ID,"PARAM_CODE":model.PARAM_CODE[0]};
			$monitorEquipmentDictParamService.createModel(model).then(function() {
				console.log("#############4");
				$.messager.alert("保存成功", "保存成功", 'info');
				_getList();
			});
		}
		/**
		 * 编辑按钮点击事件
		 */
		$scope.onEditClick = function(key) {
			$monitorEquipmentDictParamService.getModel(key).then(function(d) {
				console.log("#############2", d);
                $scope.editModel.GUID=key;
				$scope.editModel.EQUIPMENT_ID = [d.EQUIPMENT_ID];
				$scope.editModel.PARAM_CODE = [d.PARAM_CODE];
				$scope.editDialog.open();
			});
		}
		/**
		 * 编辑确认按钮点击事件
		 */
		$scope.onSubmitEditClick = function(model) {
			model["PARAM_CODE"]=model.PARAM_CODE[0];
			$monitorEquipmentDictParamService.updateModel(model).then(function() {
				console.log("#############3");
				$.messager.alert("保存成功", "保存成功", 'info');
				_getList();
				$scope.editDialog.close();
			});

		}
		/**
		 * 详情按钮点击事件
		 */
		$scope.onDetailClick = function(key) {
			$monitorEquipmentDictParamService.getList({"GUID":key}).then(function(d) {
				console.log("#############1",d);
				$scope.detailModel = d.data[0];
				console.log(d.data[0]);
				$scope.detailDialog.open();
			});
		}
		/**
		 * 删除按钮点击事件
		 */
		$scope.onDeleteClick = function(key) {
			$.messager.confirm("确认", "确定要删除这条记录吗？", function(r) {
				console.log("#############5");
				if (r) {
					$monitorEquipmentDictParamService.deleteModel(key).then(
							function() {
								$.messager.alert("删除成功", "删除成功", 'info');
								_getList();
							});
				}
			});
		}

		function _getList() {
			$monitorEquipmentDictParamService.getList().then(function(d) {
				console.error("#############6", d.data && d.data.length);
				$scope.dataList = d.data;
			});
		}
		
		_getList();
	});
}(window, angular));